package io.renren.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.stereotype.Controller;

import io.renren.entity.Area;
import io.renren.entity.Crossborderalarm;
import io.renren.entity.Crossborderalarmdetal;
import io.renren.entity.Station;
import io.renren.service.AreaService;
import io.renren.service.CrossborderalarmService;
import io.renren.service.CrossborderalarmdetalService;
import io.renren.service.StationService;
import io.renren.utils.PageUtils;
import io.renren.utils.R;


/**
 * 
 * 
 * @author zk
 * @email zk13899@163.com
 * @date 2017-06-15 09:48:21
 */
@Controller
@RequestMapping("crossborderalarmdetal")
public class CrossborderalarmdetalController {
	@Autowired
	private CrossborderalarmdetalService crossborderalarmdetalService;
	@Autowired
	private CrossborderalarmService crossborderalarmService;
	@Autowired
	private StationService stationService;
	@Autowired
	private AreaService areaService;
	private Logger logger = LoggerFactory.getLogger(getClass());
	@RequestMapping("/crossborderalarmdetal.html")

	public String list(){
		return "crossborderalarmdetal/crossborderalarmdetal.html";
	}
	
	/**
	 * 列表
	 */
	@ResponseBody
	@RequestMapping("/list")
	@RequiresPermissions("crossborderalarmdetal:list")
	public R list(Integer page, Integer limit,Integer idCrossborderalarm){
		Map<String, Object> map = new HashMap<>();
		map.put("offset", (page - 1) * limit);
		map.put("limit", limit);
		map.put("idCrossborderalarm", idCrossborderalarm);
		//查询列表数据
		List<Crossborderalarmdetal> crossborderalarmdetalList = crossborderalarmdetalService.queryList(map);
		int total = crossborderalarmdetalService.queryTotal(map);
		
		PageUtils pageUtil = new PageUtils(crossborderalarmdetalList, total, limit, page);
		
		return R.ok().put("page", pageUtil);
	}
	/* 越界报警列表 */
	@ResponseBody
	@RequestMapping("/crossborderalarm/list")

	public R crossborderalarmlist() {
		Map<String, Object> map = new HashMap<>();
		List<Crossborderalarm> listCrossborderalarm = crossborderalarmService.queryList(map);

		return R.ok().put("listCrossborderalarm", listCrossborderalarm);
	}
	/* 区域列表 */
	@ResponseBody
	@RequestMapping("/area/list")

	public R arealist() {
		Map<String, Object> map = new HashMap<>();
		List<Area> listArea = areaService.queryList(map);

		return R.ok().put("listArea", listArea);
	}
	/* 基站列表 */
	@ResponseBody
	@RequestMapping("/station/list")
	
	public R stations() {
		Map<String, Object> map = new HashMap<>();
		List<Station> listStation = stationService.queryList(map);
		
		return R.ok().put("listStation", listStation);
	}
	/* 基站列表 */
	@ResponseBody
	@RequestMapping("/station/list/{idArea}/{idCrossborderalarm}")

	public R stationlist(@PathVariable("idArea") Integer idArea,@PathVariable("idCrossborderalarm") Integer idCrossborderalarm) {
		Map<String, Object> map = new HashMap<>();
		map.put("idArea",idArea);
		map.put("idCrossborderalarm", idCrossborderalarm);
		List<Station> listStation = stationService.queryListBy_idArea_idCrossborderalarm(map);

		return R.ok().put("listStation", listStation);
	}
	/**
	 * 信息
	 */
	@ResponseBody
	@RequestMapping("/info/{id}")
	@RequiresPermissions("crossborderalarmdetal:info")
	public R info(@PathVariable("id") Integer id){
		Crossborderalarmdetal crossborderalarmdetal = crossborderalarmdetalService.queryObject(id);
		
		return R.ok().put("crossborderalarmdetal", crossborderalarmdetal);
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@RequestMapping("/save")
	@RequiresPermissions("crossborderalarmdetal:save")
	public R save(@RequestBody Crossborderalarmdetal crossborderalarmdetal){
		crossborderalarmdetalService.save(crossborderalarmdetal);
		
		return R.ok();
	}
	
	/**
	 * 批量保存
	 */
	@ResponseBody
	@RequestMapping("/addBatch")
	public R saves(@RequestBody List<Crossborderalarmdetal> list){
for (Crossborderalarmdetal string : list) {
	this.logger.info("ids={}"+string.getIdStation());
}
		crossborderalarmdetalService.addBatch(list);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("crossborderalarmdetal:update")
	public R update(@RequestBody Crossborderalarmdetal crossborderalarmdetal){
		crossborderalarmdetalService.update(crossborderalarmdetal);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@ResponseBody
	@RequestMapping("/delete")
	@RequiresPermissions("crossborderalarmdetal:delete")
	public R delete(@RequestBody Integer[] ids){
		crossborderalarmdetalService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
